{extend name="base/base" /}
{block name="main"}
<style>
.layui-form-pane .layui-form-label{width: 130px;}
.layui-form-pane .layui-input-block{
        margin-left: 130px;
}
</style>
<form id="form" method="post" class="layui-form layui-form-pane" action="{:url('/admin/buliao-edit')}">
	<!--<div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            {form:select name="type_id" list="$typelist" value="$list['type_id']" option="['lay-verif'=>'required']"}
        </div>
    </div>-->
	
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>面料名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input"
                   value="{:isset($list.title)?$list.title:''}" {if condition="isset($list['b_id'])" }lay-verify="required"{else /}
            lay-verify="required|title"{/if}>
        </div>
    </div>
	<!--
    <div class="layui-form-item">
        <label class="layui-form-label">英文名称</label>
        <div class="layui-input-block">
            <input type="text" name="title_eng" placeholder="请输入" autocomplete="off" class="layui-input"
                   value="{:isset($list.title_eng)?$list.title_eng:''}" {if condition="isset($list['b_id'])" }lay-verify="required"{else /}
            lay-verify="required|title_eng"{/if}>
        </div>
    </div>-->
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>面料编码</label>
        <div class="layui-input-block">
            <input type="text" name="code" placeholder="请输入" autocomplete="off" class="layui-input"
                   value="{:isset($list.code)?$list.code:''}" lay-verify="required">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>中文描述</label>
        <div class="layui-input-block">
            <input type="text" name="info" placeholder="请输入"  value="{:isset($list.info)?$list.info:''}"  autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>英文描述</label>
        <div class="layui-input-block">
            <input type="text" name="info_eng" placeholder="请输入"  value="{:isset($list.info_eng)?$list.info_eng:''}"  autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <!--<div class="layui-form-item">-->
    <!--    <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>等级</label>-->
    <!--    <div class="layui-input-block">-->
    <!--        <input type="text" name="level" placeholder="请输入"  value="{:isset($list.level)?$list.level:''}"  autocomplete="off" class="layui-input" lay-verify="required">-->
    <!--    </div>-->
    <!--</div>-->
    	
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>布料等级</label>
        <div class="layui-input-block">
            <select name="level" lay-verify="required">
				{volist name="levellist" id="vo"}
                <option {if isset($list['level'])}{eq name="list['level']" value="$vo['title']"}selected=""{/eq}{/if} value="{$vo['title']}">{$vo['title']}</option>
				{/volist}
            </select>           
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;"></span>防火描述</label>
        <div class="layui-input-block">
            <input type="text" name="fh" placeholder="请输入"  value="{:isset($list.fh)?$list.fh:''}"  autocomplete="off" class="layui-input" lay-verify="">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">防火英文描述</label>
        <div class="layui-input-block">
            <input type="text" name="fh_eng" placeholder="请输入"  value="{:isset($list.fh_eng)?$list.fh_eng:''}"  autocomplete="off" class="layui-input" >
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;"></span>背板描述</label>
        <div class="layui-input-block">
            <input type="text" name="beiban" placeholder="请输入"  value="{:isset($list.beiban)?$list.beiban:''}"  autocomplete="off" class="layui-input" >
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;"></span>英文背板描述</label>
        <div class="layui-input-block">
            <input type="text" name="beiban_eng" placeholder="请输入"  value="{:isset($list.beiban_eng)?$list.beiban_eng:''}"  autocomplete="off" class="layui-input" lay-verify="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>失效标识</label>
        <div class="layui-input-block">
            <select name="status">
                <option {if isset($list['status'])}{eq name="list['status']" value="1"}selected=""{/eq}{/if} value="1">有效</option>
                <option {if isset($list['status'])}{eq name="list['status']" value="2"}selected=""{/eq}{/if} value="2">预失效</option>
                <option {if isset($list['status'])}{eq name="list['status']" value="3"}selected=""{/eq}{/if} value="3">失效</option>
            </select>    
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <input type="text" name="remark" placeholder="请输入"  value="{:isset($list.remark)?$list.remark:''}"  autocomplete="off" class="layui-input">
        </div>
    </div>
    
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="b_id" value="{:isset($list['b_id'])?$list['b_id']:''}">
            <input type="hidden" name="__token__" id="token" value="{$Request.token}"/>
            <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
{css href="/form-select/formSelects-v4.css" /}
<script>
    layui.config({
        base: '/form-select/' //此处路径请自行处理, 可以使用绝对路径
    }).extend({
        formSelects: 'formSelects-v4'
    });
    layui.use(['form', 'jquery', 'formSelects','upload'], function () {
        var formSelects = layui.formSelects, form = layui.form, $ = layui.jquery,upload = layui.upload;
        
        //上传头像
		upload.render({
			elem: '.userFaceBtn',
			url: "{:url('/admin/upload')}",
			accept:'images',
			acceptMime:'image/*',
			done: function(data){
				var icon=5;
				if(!data.code){
					icon=6;
					$('#userFace').attr('src',data.data.src);
					$('#head').val(data.data.src);
				}
				layer.msg(data.msg, {icon:icon,time: 1500});
			},
			error: function(){
				layer.msg('上传失败', {icon:icon,time: 1500});
			}
		});
		
        formSelects.on('selectId', function (id, vals, val, isAdd, isDisabled) {
            $('#group_id').val(layui.formSelects.value(id, 'val'));
        }, true);
        //表单验证
        form.verify({
            title: function (value, item) { //value：表单的值、item：表单的DOM对象
                var msg;
                $.ajax({
                    async: false,
                    url: "{:url('/admin/buliao-check')}",
                    data: {title: value},
                    success: function (data) {
                        if (data.code== 0) {
                            msg = data.msg;
                        }
                    }
                });
                return msg;
            },
            password:function(value, item){
                if(value){
                    if(!(/^[\w\W]{6,25}$/.test(value))){
                        return '用户名不能全为数字';
                    }
                }
            },
            uploadimg:function(value, item){
                if(!value){
                    return '请上传图片';
                }
            }
        });
        //表单提交
        form.on("submit(*)", function (data) {
            var obj = $(this);
            obj.attr("disabled", "disabled").addClass("layui-disabled");
            $.post(data.form.action, data.field, function (data) {
                var icon = 5;
                if (data.code) {
                    icon = 6;
                }
                layer.msg(data.msg, {icon: icon, time: 1500}, function () {   //提示的插件，可以使用alert代替
                    if (data.code) {
                        setTimeout(function () {
                            //刷新父页面
                            parent.location.reload();
                        }, 500);
                    } else {
                        $('#token').val(data.data.token);
                        obj.removeAttr("disabled").removeClass("layui-disabled");
                    }
                });
            }, 'json');
            return false;
        });
    });


</script>
{/block}